# 1为ARJ 111架机，2为C919 104架机
import pandas as pd
# 打开文件
# path = r'E:\试飞数据\处理后ADS-B数据\20241014\ADSB2024-10-14(B001E).txt'
from pandas import DataFrame
# 设置读取和存储路径
file = '20241022'

## 104架机 ADS-B数据
ADS_B_file_name2 = 'ADSB2024-10-21(B3328)'

#读取路径
path2 = r'E:\试飞数据\原始ADS-B数据' + '\\' + file + '\\' +ADS_B_file_name2 + '.xlsx'

# 读取数据
df2 = pd.read_excel(path2)

list2 = []


for i in range(df2.shape[0]):
    list2.append(df2['创建时间'][i][11:])

plane_info = ['纬度','经度','高度(M)','地速(KM/H)','航向']

df_rearrange2 = df2.reindex(columns = plane_info)

df_rearrange2.columns = ['latitude_2','longitude_2','altitude_2','ground_speed_2','magnetic_2']

df_rearrange2.insert(5, 'time', list2, allow_duplicates=False)

df_rearrange2['time'] = pd.to_datetime(df_rearrange2['time'], format="%H:%M:%S")

df_rearrange2 = df_rearrange2.drop_duplicates('time')

df_rearrange2 = df_rearrange2.set_index('time')

df_rearrange2 = df_rearrange2.resample('500ms', origin='start').interpolate(method='linear')

df_rearrange2.index = df_rearrange2.index.strftime("%H:%M:%S:%f")
#
path_out2 = r'E:\试飞数据\双机试飞数据'+ '\\'+ file + '\\' + ADS_B_file_name2+'修2_2Hz.txt'

#输出到指定路径下
df_rearrange2.to_csv(path_out2, sep='\t')